/**
 * Created by yangfan on 2016/10/12.
 */
define(['config/appregister',"i18n","business/myResume/services/httpServices","jquery"],function(app,i18n,httpServices){
    app.controller('resumePostedCtrl', function($scope,$state) {
        $scope.i18n = i18n;
        $scope.listParams = {
            pageNo:1,
            pageSize:30,
            keyWord:''
        };

        $scope.tableTitle = ["职位","公司名称","工作地点","薪资","发布日期"];
        $scope.searchKeyWord = function(){
            getList()
        };
        function getList(){
            var req = {
                type:"GET",
                uri:"getMyDeliveryJob",
                data:{
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.listParams.pageSize,
                    type:0,
                    keyWord:$scope.listParams.keyWord
                }
            };
            httpServices.jobServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.jobList = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    getPage();
                });
            }).error(function(){})
        }
        //批量设为意向公司
        $scope.targetJob = function(item){
            /*if(item.targetCompanyFlag){
                console.log($('.icon2').length);
            }else{
                if($('.icon2').length == 3){
                    $('.target-more').show();
                    return;
                }
            }*/
        	var req = {
                type:"PUT",
                uri:"targetJob",
                data:{
                    jobIds:item.jobId
                }
            };
            httpServices.jobServices(req).success(function(response){
                $scope.$apply(function(){
                    if(response.code != 0){
                        if($('.icon2').length == 3){
                            $('.target-more').show();
                            return;
                        }
                    }
                    if(item.targetCompanyFlag){
                        item.targetCompanyFlag = 0;
                    }else{
                        item.targetCompanyFlag = 1;
                    }

                    //getList();
                });
            }).error(function(){})
        	
        }
        $('.target-more span').on('click',function(){
        	$('.target-more').hide();
        })
        function getPage(){
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage: $scope.listParams.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function () {
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getList();
                }
            };
            $scope.everPageShow = $scope.paginationConf.perPageOptions;

        }
        getList()
    })
});
